package org.huang.zhen;

public class Block {
    private volatile int[][] mMap;
    public Block(int[][] map) {
        mMap = map;
    }

    public void rotate() {
        int mapX = mMap.length;
        int mapY = mMap[0].length;
        // 矩阵翻转，交换X,Y
        int [][]map = new int[mapY][mapX];
        for (int i = 0; i < mapX; i++) {
            for (int j = 0; j < mapY; j++) {
                map[j][mapX - i - 1] = mMap[i][j];
            }
        }
        mMap = map;
    }

    public int[][] getMap() {
        return mMap;
    }

    public String toString() {
        StringBuilder result = new StringBuilder();
        for (int i = 0; i < mMap.length; i++) {
            for (int j = 0; j < mMap[i].length; j++) {
                result.append(mMap[i][j]).append(" ");
            }

            result.append("\n");
        }
        return result.toString();
    }

    public int getWidth () { return mMap[0].length;}

    public int getHeight () { return mMap.length;};
}
